Skip to content

feat: add data migration to sync DiscussionsConfiguration with modulestore tab.is_hidden#38294

Open
Anas12091101 wants to merge 3 commits intoopenedx:masterfrom
mitodl:anas/data-migration-to-sync-discussion
Open

feat: add data migration to sync DiscussionsConfiguration with modulestore tab.is_hidden#38294
Anas12091101 wants to merge 3 commits intoopenedx:masterfrom
mitodl:anas/data-migration-to-sync-discussion

Conversation

@Anas12091101
Copy link
Copy Markdown
Contributor

@Anas12091101 Anas12091101 commented Apr 7, 2026

Description

We introduced a fix in #38084 to synchronize DiscussionsConfiguration.enabled (DB) with tab.is_hidden (modulestore) during course imports. While this resolves the issue for newly imported courses, existing courses that are currently out of sync still need to be updated so that course authors see the correct values.

This PR adds a data migration that reads each course's discussion tab from CourseOverviewTab (a DB-level cache of modulestore tabs) and updates both DiscussionsConfiguration.enabled and CourseAppStatus.enabled to match (enabled = NOT is_hidden). Only out-of-sync rows are updated. The migration uses CourseOverviewTab instead of the modulestore directly to avoid performance issues at scale.

Useful information to include:

  • Which edX user roles will this change impact? Course Author"
  • Include screenshots for changes to the UI (ideally, both "before" and "after" screenshots, if applicable).
  • Provide links to the description of corresponding configuration changes. Remember to correctly annotate these
    changes.

Supporting information

#38084 (comment)

Testing instructions

  1. Rollback 0019 if already applied:
python manage.py migrate discussions 0018
  1. Create unsynced data in the shell:
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview, CourseOverviewTab
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
from openedx.core.djangoapps.course_apps.models import CourseAppStatus
from opaque_keys.edx.keys import CourseKey

course_key = CourseKey.from_string("course-v1:U0X12+CS11013+UAI_22")

overview, _ = CourseOverview.objects.get_or_create(id=course_key, defaults={"version": 1})

tab, _ = CourseOverviewTab.objects.update_or_create(
    course_overview=overview,
    tab_id="discussion",
    defaults={"is_hidden": True},
)

config, _ = DiscussionsConfiguration.objects.update_or_create(
    context_key=course_key,
    defaults={"enabled": True},
)

app_status, _ = CourseAppStatus.objects.update_or_create(
    course_key=course_key,
    app_id="discussion",
    defaults={"enabled": True},
)

# Verify the desync
print(f"Tab is_hidden: {tab.is_hidden}")            # True
print(f"Config enabled: {config.enabled}")           # True  (should be False)
print(f"AppStatus enabled: {app_status.enabled}")    # True  (should be False)
  1. Visit the Pages and Resources page in the authoring MFE and verify that the discussion configuration is unsynced

  2. Run the migration:

python manage.py migrate discussions 0019
  1. Verify the fix:
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
from opaque_keys.edx.keys import CourseKey

6. Repeat step 3 and verify that the configuration is now synced

config = DiscussionsConfiguration.objects.get(context_key=CourseKey.from_string("course-v1:TestOrg+Test101+2026"))
print(f"Config enabled: {config.enabled}")  # Should now be False

Deadline

"None"

Other information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.
  • If your database migration can't be rolled back easily.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 7, 2026
@openedx-webhooks
Copy link
Copy Markdown

Thanks for the pull request, @Anas12091101!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@Anas12091101 Anas12091101 force-pushed the anas/data-migration-to-sync-discussion branch from ff22569 to f07de7f Compare April 7, 2026 12:24
@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Apr 8, 2026
Copy link
Copy Markdown
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple requests, looks good otherwise.

Comment on lines +112 to +114
# Also update CourseAppStatus to keep the Pages & Resources UI in sync.
# The update_course_apps_status task may run before this handler due to
# the COURSE_PUBLISH_TASK_DELAY countdown, caching a stale enabled value.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the code here. We have 2 scenarios:

New course: No CourseAppStatus row exists yet. The handler creates one with the correct enabled value.
Old course: A CourseAppStatus row already exists (created by update_course_apps_status on a previous publish, or by initialize_course_app_status on first MFE page load). The handler updates it.

could you add an assertion for each of those scenarios into https://github.com/openedx/openedx-platform/blob/master/openedx/core/djangoapps/discussions/tests/test_handlers.py ?

Comment on lines +1 to +13
"""
Sync DiscussionsConfiguration.enabled and CourseAppStatus.enabled with
CourseOverviewTab.is_hidden.

When a course is imported, the discussion tab's is_hidden value is carried over
from the source course. However, DiscussionsConfiguration.enabled and
CourseAppStatus.enabled default to True and are not updated from the imported
tab state, causing a desync.

This migration reads each discussion tab from CourseOverviewTab (a DB cache of
course tabs) and sets both DiscussionsConfiguration.enabled and
CourseAppStatus.enabled to NOT is_hidden.
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you clarify that this is a backfill for existing courses, whereas the sync going forward is handled by update_course_discussion_config ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

4 participants